package com.nlelpct.system.service.impl;

import com.nlelpct.constant.SystemConstant;
import com.nlelpct.excel.ExcelExportData;
import com.nlelpct.excel.ExcelUtils;
import com.nlelpct.security.utils.GetLoginInfoUtils;
import com.nlelpct.system.feign.EsAuthenticationFeignService;
import com.nlelpct.system.model.query.AuthenticationLogQueryVo;
import com.nlelpct.system.model.vo.EsAuthenticationLogForExcelVo;
import com.nlelpct.system.model.vo.EsAuthenticationLogReturnVo;
import com.nlelpct.utils.Result;
import com.nlelpct.utils.TimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author 刘伟涛
 * @Date 2023/10/26 17:32
 **/
@Service
@Slf4j
public class EsAuthenticationLogService {
    private final EsAuthenticationFeignService esAuthenticationFeignService;


    @Autowired
    public EsAuthenticationLogService(EsAuthenticationFeignService esAuthenticationFeignService) {
        this.esAuthenticationFeignService = esAuthenticationFeignService;
    }

    /**
     * 查询认证日志集合
     */
    public Result getAuthenticationLogByPage(AuthenticationLogQueryVo queryVo) {
        queryVo.setCompanyId(this.getCurrentCompanyId());
        queryVo.setSystemId(this.getCurrentSystemId());
        log.info("======当前的companyId为========>{}", GetLoginInfoUtils.getCompanyId());
        return esAuthenticationFeignService.getAuthenticationLogByPage(queryVo);
    }


    /**
     * 通过Id查询认证日志详情
     */
    public Result getOptLogById(String id) {
        return esAuthenticationFeignService.getOptLogById(id);
    }

    /**
     * 查询认证日志认证类型
     */
    public Result getAuthenticationOperationType() {
        return esAuthenticationFeignService.getAuthenticationOperationType();
    }

/*    public void exportEsAuthenticationLogByIds(String id, HttpServletResponse response) {
        //获取数据
        EsAuthenticationLogReturnVo data = esAuthenticationFeignService.exportAuthenticationExcelById(id);

        EsAuthenticationLogForExcelVo esAuthenticationLogForExcelVo = new EsAuthenticationLogForExcelVo();
        esAuthenticationLogForExcelVo.setId(data.getId())
                .setAuthenticationType(data.getContent().get("authenticationType"))
                .setAuthenticationWay(data.getAuthenticationWay())
                .setIpAddress(data.getContent().get("ipAddress"))
                .setOperateTime(data.getOperateTime()).setOperatorName(data.get)
        //构建excelExportData
        ExcelExportData excelExportData = new ExcelExportData()
                .setFileName(SystemConstant.EMPLOYEE_EXCEL_FILE_PRE + TimeUtils.getTime("yyyyMMdd") + SystemConstant.EXCEL_FILE_SUFFIX)
                .setResponse(response)
                .setList(sysEmployeeListVos)
                .setSheetName(SystemConstant.EMPLOYEE_SHEET_NAME)
                .setClazz(SysEmployeeListVo.class);

        //构建并下载
        try {
            ExcelUtils.exportExcel(excelExportData);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }*/


    /**
     * 获取当前系统ID
     *
     * @return 系统ID
     */
    public String getCurrentSystemId() {
        return GetLoginInfoUtils.getSystemId();
    }

    /**
     * 获取员工ID
     * @return 员工ID
     */
    public String getCurrentEmployeeId() {
        return GetLoginInfoUtils.getEmployeeId();
    }

    /**
     * 获取企业ID
     * @return 企业ID
     */
    public String getCurrentCompanyId() {
        return GetLoginInfoUtils.getCompanyId();
    }
}
